//
//  LPNineTenwtySixOnlineSchoolViewController.m
//  ShangHaiHuDongApp
//
//  Created by liuyingping on 2018/9/26.
//  Copyright © 2018年 刘应平. All rights reserved.
//

#import "LPNineTenwtySixOnlineSchoolViewController.h"
#import "GTPageController.h"
#import "ZJAdditions.h"
#import "LPGTBaseOnlineSchoolViewController.h"
@interface LPNineTenwtySixOnlineSchoolViewController ()
{
    GTPageController *_pageController;/**< 首页框架 */
    
}

/** 栏目数组 */
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation LPNineTenwtySixOnlineSchoolViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self netWorking];
    self.titlelabel.text = @"网上党校";
}

#pragma mark - 初始化控制器
- (void)initUIWithPageController{
    //框架
    _pageController = [self getDefaultController];
    
    _pageController.view.frame = CGRectMake(0, LP_TopHeight, [UIScreen zj_screenWith], [UIScreen zj_screenHeight] - LP_TopHeight);
    
    [self.view addSubview:_pageController.view];
    [self addChildViewController:_pageController];
    
}

- (GTPageController *)getDefaultController{
    LPGTBaseOnlineSchoolViewController *vc = [[LPGTBaseOnlineSchoolViewController alloc]init];
    NSArray *titles = @[@"党规党训", @"党史党建", @"保密意识培训", @"两学一做", @"三会一课"];
    __block NSMutableArray *titlesWidth = [NSMutableArray array];
    __block NSMutableArray *viewControllers = [NSMutableArray array];
    [titles enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [titlesWidth addObject:@([NSString zj_sizeOfString:obj font:[UIFont systemFontOfSize:16] width:[UIScreen zj_screenWith]].width + 5 * [UIScreen zj_screenWScale])];
        [viewControllers addObject:[vc class]];
        
    }];
    
    GTPageController *pageVC = [[GTPageController alloc] initWithViewControllerClasses:viewControllers andTheirTitles:titles];
    pageVC.lpNewsColmModelArray = self.dataArray;
    pageVC.pageAnimatable = YES;
    pageVC.itemsWidths = titlesWidth;
    pageVC.postNotification = YES;
    pageVC.menuBGColor = [UIColor whiteColor];
    pageVC.menuViewStyle = GTMenuViewStyleLine;
    pageVC.titleColorNormal = [UIColor zj_colorWithHexString:@"626262"];
    
    return pageVC;
}


#pragma mark - 网络请求
- (void)netWorking{
    [YJProgressHUD showMessage:@"加载中..." duration:10 view:self.view];
    __weak typeof(self) weakSelf = self;
    [NetWorkingManager postWithUrlString:[NetWorkingURL getSt] Parameter:nil Success:^(id object) {
        [YJProgressHUD hide];
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            weakSelf.dataArray = [[NSArray yy_modelArrayWithClass:[ZJStudySpcialModel class] json:[object objectForKey:@"ST_CLASS"]] mutableCopy];
            [weakSelf initUIWithPageController];
            
        }else{
            [YJProgressHUD showMsgWithoutView:@"加载失败"];
        }
        
    } Fail:^(id object) {
        [YJProgressHUD showMsgWithoutView:@"加载失败"];
    }];
}



- (NSMutableArray *)dataArray{
    if (_dataArray == nil){
        _dataArray = [NSMutableArray array];
        
    }
    return _dataArray;
}

@end
